<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>docuidwia.com</h1>
    <h1>d后盾人</h1>
    <h1>dowimuucx.cn</h1>
  </body>
</html>

<script>
  function search(string, reg) {
    let result = [];
    while ((res = reg.exec(string))) {
      result.push(res);
    }
    return result;
  }

  let matchs = search(document.body.innerHTML, /<(h[1-6])>([\s\S]+?)<\/\1>/gi);
  console.dir(matchs);
</script>
